package com.jfinal.aceadmin.model;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.jfinal.aceadmin.util.ConstantKit;

@Repository
public class CommodityRecordImpl {

	private static ApplicationContext ctx;

	public static CommodityRecordImpl getDAO() {
		if (null == ctx) {
			ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		}
		CommodityRecordImpl instance = ctx.getBean(CommodityRecordImpl.class);
		return instance;
	}

	public void operateModel(String id, String oper,
			CommodityRecord commodityRecord) {
		if (ConstantKit.BLANK_ID.equals(id)) {
			commodityRecord.save();
		} else {
			if (ConstantKit.OPER_EDIT.equals(oper)) {
				commodityRecord.setId(Integer.parseInt(id));
				commodityRecord.update();
			} else {
				commodityRecord.setId(Integer.parseInt(id));
				commodityRecord.delete();
			}
		}
	}
}
